package org.acme.server.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.acme.server.mapper.SysServerMapper;
import org.acme.server.po.SysServer;
import org.acme.server.utils.IPUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author chentao
 * @version 1.0
 * @description: TODO
 * @date 2025/3/7 下午10:51
 */
@Service
public class SysServerServiceImpl extends ServiceImpl<SysServerMapper, SysServer> implements SysServerService {

    @Value("${server.port}")
    private int port;

    /***
     *
     * @return
     */
    @Override
    public String getIp() {
        return IPUtils.getIP();
    }

    @Override
    public int getPort() {
        return this.port;
    }

    /****
     * 获取当前节点的id
     * @return
     */
    @Override
    public long getServerId() {
        return IPUtils.combineIpAndPort(getIp(),getPort());
    }

    /****
     * 获取所有的节点
     * @return
     */
    @Override
    public List<Long> getServerIds() {
        return getBaseMapper().getServerIds();
    }

    /***
     * 获取当前节点
     * @return
     */
    @Override
    public SysServer getCurrentSysServer() {
        return getById(getServerId());
    }


    /***
     * 查询所有的节点
     * @return
     */
    @Override
    public List<SysServer> getAllServer() {
        return list();
    }
}
